﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfDependencyProperty_Base
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private Student stu;
        public MainWindow()
        {
            InitializeComponent();

            // 绑定stu与textBox1,将textBox1作为源,stu作为目标
            this.stu = new Student();
            Binding binding = new Binding("Text") { Source = this.textBox1 };
            BindingOperations.SetBinding(stu, Student.NameProperty, binding);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Student stu = new Student();
            //stu.SetValue(Student.NameProperty, this.textBox1.Text);
            //this.textBox2.Text = (string)stu.GetValue(Student.NameProperty);
            MessageBox.Show(this.stu.GetValue(Student.NameProperty).ToString());
        }
    }
}
